package com.smile.http;

import com.smile.data.dto.ProductMenuQueryDto
import com.smile.data.dto.ProductMenuUpdateDto
import com.smile.data.entity.ProductMenuEntity
import com.smile.response.ResultEmpty
import com.smile.response.ResultPage
import com.smile.service.ProductMenuService
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = ["菜单管理"])
@RestController
@RequestMapping("/products/menus")
public class ProductMenuController {
    @Autowired
    lateinit var service : ProductMenuService;

    @GetMapping
    @ApiOperation("分页查询")
    fun query(dto: ProductMenuQueryDto) : ResultPage<ProductMenuEntity> {
        return service.query(dto);
    }

    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    fun queryById( @PathVariable id : String ) : ProductMenuEntity{
    return  service.queryById(id);
    }

    @PostMapping
    @ApiOperation("创建菜单")
    fun create(@RequestBody dto : ProductMenuEntity) : ResultEmpty {
        return service.create(dto);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改菜单")
    fun update(@PathVariable  id: String,@RequestBody dto : ProductMenuEntity) : ResultEmpty {
        return service.update(id, dto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    fun remove(@PathVariable id: String) :ResultEmpty {
        return service.remove(id);
    }

}
